#include "GameFileManager.h"

#include "utilities/Files.h"

std::vector< std::string > GameFileManager::GetFileList() const
{
	std::vector< std::string > fileListRaw = GetFileListRaw();
	std::vector< std::string > fileList;

	for ( size_t i = 0; i < fileListRaw.size(); ++i )
	{
		std::string filename = fileListRaw[ i ];

		if ( filename.length() <= 9 )
		{
			// There isn't even enough room for the extension, so it isn't valid.
			continue;
		}

		std::string filenameEnd = filename.substr( filename.length() - 10 );

		if ( filenameEnd != ".game-save" )
		{
			// Not a real save, keep going.
			continue;
		}

		// Found a real file, add it to the list.
		fileList.push_back( filename.substr( 0, filename.length() - 10 ) );
	}

	return fileList;
}

std::vector< std::string > GameFileManager::GetFileListRaw() const
{
	return util::GetFileListing( "./saves" );
}
